/**
 * 
 * @authors Tao (972990430@qq.com)
 * @date    2017-07-09 17:37:35
 * @version $Id$
 */
/*-------------------------------------------客户管理--------------------------------*/
backHomeApp.controller('customerManageCtrl', ['$scope', "DPUtil", "customerService", "$uibModal", "UIUtil", "brandManageService", "carManageService", "storeManageService", "salesmanManageService", "$rootScope","itemService",
    function($scope, DPUtil, customerService, $uibModal, UIUtil, brandManageService, carManageService, storeManageService, salesmanManageService, $rootScope,itemService) {
        $scope.conditions = {};
        $scope.g_clientType = [];
        $scope.g_document = [];
        $scope.g_condition = [];
        $scope.g_preResult = [];
        $scope.g_finallyResult = [];
        $scope.g_periods = [];
        $scope.myItem= [];
        // 获取大小项目
        $scope.getMyItem =function(){
            if ($scope.myItem.length>0) {
                return false;
            }
            itemService.list({
                page: 1,
                rows: 9000
            }).then(function(data) {
                $scope.myItem = data.content;
                for (var i = 0; i < $scope.myItem.length; i++) {
                    if ($scope.myItem[i].type == "客户属性") {
                        $scope.g_clientType.push($scope.myItem[i]);
                    } else if ($scope.myItem[i].type == "进件文件") {
                        $scope.g_document.push($scope.myItem[i]);
                    } else if ($scope.myItem[i].type == "上牌人情况") {
                        $scope.g_condition.push($scope.myItem[i]);
                    } else if ($scope.myItem[i].type == "预审结果") {
                        $scope.g_preResult.push($scope.myItem[i]);
                    } else if ($scope.myItem[i].type == "终审结果") {
                        $scope.g_finallyResult.push($scope.myItem[i]);
                    } else if ($scope.myItem[i].type == "期数") {
                        $scope.g_periods.push($scope.myItem[i]);
                    }
                }
            });
        }
        $scope.getMyItem();
        // data:大小项数据列表
        // key:大小项id（value）
        // keyName:大小项值（keyword）
        /*$scope.getItemKey = function(data,key,obj,keyName){
            if (key&&data.length>0) {
                for (var i = 0; i < data.length; i++) {
                    if (key==data[i].value) {
                        obj[keyName] = data[i].keyword;
                        break;
                    }
                }
            }
            
        }*/
        DPUtil.initPage($scope, $scope.conditions);
        /*$scope.getAllData = function() {
            brandManageService.allList().then(function(data) {
                $scope.brands = data;
            });
            var obj = {
                page: 1,
                rows: 999999
            }
            carManageService.list(obj).then(function(data) {
                $scope.cars = data.content;
            });
            storeManageService.list(obj).then(function(data) {
                $scope.stores = data.content;
            });
            salesmanManageService.list(obj).then(function(data) {
                $scope.sells = data.content;
            });
        }*/
        // $scope.getAllData();
        $scope.getBrand = function() {
            brandManageService.allList().then(function(data) {
                $scope.brands = data;
            });
        }
        $scope.getBrand();
        /*$scope.getStore = function() {
            storeManageService.allList($scope.customer.brand_id).then(function(data) {
                $scope.stores = data.content;
            });
        }
        $scope.getCar = function() {
            brandManageService.allList().then(function(data) {
                $scope.brands = data;
            });
        }
        $scope.getsalesman = function() {
            brandManageService.allList().then(function(data) {
                $scope.brands = data;
            });
        }*/
        $scope.getStore = function() {
            var param = $scope.conditions.select_brand ? $scope.conditions.select_brand.id : "";
            storeManageService.allList(param).then(function(data) {
                $scope.conditions.select_store = null;
                $scope.conditions.select_sell = null;
                $scope.sells = [];
                $scope.stores = data;
            });
        }
        $scope.getSale = function() {
            var obj_sale = {
                companyId: $scope.conditions.select_store ? $scope.conditions.select_store.id : "",
                page: 1,
                rows: 999999,
                select_store: $scope.conditions.select_store
            }
            salesmanManageService.list(obj_sale).then(function(data) {
                $scope.conditions.select_sell = null;
                $scope.sells = data.content;
            });
        }
        /**
         * [query 查询]
         */
        $scope.query = function(type) {
            if (type) {
                $scope.conditions.page = 1;
            };
            $scope.conditions.intoStartDate = DPUtil.getDateToString($scope.conditions.start_date);
            $scope.conditions.intoEndDate = DPUtil.getDateToString($scope.conditions.end_date);
            customerService.list($scope.conditions).then(function(data) {
                $scope.data = data.content;
                $scope.total = data.recordCount;
            });
        };
        $scope.query();


        /**
         * [changePageSize 分页数量]
         */
        $scope.changePageSize = function() {
            $scope.conditions.rows = $scope.page_size.value;
            $scope.conditions.page = 1;
            $scope.query();
        };

        $scope.clearQuery = function() {
            DPUtil.cleanQuery($scope.conditions);
        }
        /**
         * [add 新增]
         */
        $scope.add = function() {
            $scope.getMyItem();
            _fn.showAdd();
        };

        /**
         * [update]
         */
        $scope.update = function(key) {
            $scope.getMyItem();
            var stores = [],cars=[],sells=[],clientSelect=[];
            if (!key.brandId) {
                _fn.showUpdate(key, stores, cars, sells,clientSelect);
                return false;
            }
            storeManageService.allList(key.brandId).then(function(data) {
                stores = data;
                /*var obj = {
                    brandId: key.brandId,
                    id: key.companyId,
                }*/
                if (!key.companyId) {
                    _fn.showUpdate(key, stores, cars, sells,clientSelect);
                    return false;
                }
                carManageService.getListByCompany(key.companyId).then(function(data) {
                    /*for (var i = 0; i < data.length; i++) {
                        data[i].id = data[i].carId;
                        data[i].name = data[i].carName;
                    }*/
                    cars = data;
                    var obj_sale = {
                        companyId: key.companyId,
                        page: 1,
                        rows: 999999,
                    }
                    salesmanManageService.list(obj_sale).then(function(data) {
                        sells = data.content;
                        if (!key.carId||!key.periods) {
                            _fn.showUpdate(key, stores, cars, sells,clientSelect);
                            return false;
                        }
                        carManageService.getListByCarAndPeriods(key.carId,key.periods).then(function(data){
                            if (data.length>0) {
                                for (var i = 0; i < data.length; i++) {
                                    clientSelect.push(data[i].clientRate);
                                }      
                            }
                            _fn.showUpdate(key, stores, cars, sells,clientSelect);
                        });
                        
                    });
                    
                });

            });
        };
        /**
         * [detail]
         */
        $scope.detail = function(key) {
            $scope.getMyItem();
            customerService.detail(key.id).then(function(data){
                _fn.showDetail(data.content);
            });
            
        };

        $scope.delete = function(id) {
            UIUtil.comfirm({
                content: "确定删除该客户吗？",
                ok: function() {
                    customerService.delete(id).then(function(data) {
                        if (data.success) {
                            UIUtil.alert({ content: data.successMessage });
                            $scope.query();
                        } else {
                            UIUtil.alert({ content: data.failureMessage });
                        };
                    })
                }
            })

        }

        /**
         * [_fn 私有方法对象]
         * @type {Object}
         */
        var _fn = {
            /**
             * [showAdd 显示窗口]
             */
            showAdd: function() {
                $uibModal.open({
                    animation: true,
                    templateUrl: 'add.html',
                    keyboard: false,
                    backdrop: 'static',
                    size: "sg",
                    controller: ["$scope", "$uibModalInstance",
                        function(add_scope, uibModal) {

                            add_scope.g_clientType = $scope.g_clientType;
                            add_scope.g_document = $scope.g_document;
                            add_scope.g_condition = $scope.g_condition;
                            add_scope.g_preResult = $scope.g_preResult;
                            add_scope.g_finallyResult = $scope.g_finallyResult;
                            add_scope.g_periods = $scope.g_periods;
                            add_scope.customer = {};
                            add_scope.title = "添加";
                            add_scope.brands = $scope.brands;
                            add_scope.cars = [];
                            add_scope.stores = [];
                            add_scope.sells = [];
                            add_scope.customer.request_date = new Date();
                            add_scope.getStore = function() {
                                var param = add_scope.customer.select_brand ? add_scope.customer.select_brand.id : "";
                                if (param) {
                                    storeManageService.allList(param).then(function(data) {
                                        add_scope.customer.select_store = null;
                                        // add_scope.cars = [];
                                        // add_scope.sells = [];
                                        add_scope.stores = data;
                                        add_scope.customer.select_car = null;
                                        add_scope.cars = [];
                                        add_scope.customer.select_sell = null;
                                        add_scope.sells = [];
                                        add_scope.clientSelect = [];
                                        add_scope.customer.clientRate ='',add_scope.customer.dealerRate='',add_scope.customer.venderRate='';
                                    });
                                }
                                
                            }
                            add_scope.getCar = function() {
                                /*var obj = {
                                    brandId: add_scope.customer.select_brand.id,
                                    id: add_scope.customer.select_store ? add_scope.customer.select_store.id : "",
                                }
                                storeManageService.detail(obj).then(function(data) {
                                    for (var i = 0; i < data.length; i++) {
                                        data[i].id = data[i].carId;
                                        data[i].name = data[i].carName;
                                    }
                                    add_scope.customer.select_car = null;
                                    add_scope.cars = data;
                                });*/
                                var id = add_scope.customer.select_store ? add_scope.customer.select_store.id : ""
                                if (id) {
                                    carManageService.getListByCompany(id).then(function(data){
                                        add_scope.customer.select_car = null;
                                        add_scope.cars = data;
                                        add_scope.clientSelect = [];
                                        add_scope.customer.clientRate ='',add_scope.customer.dealerRate='',add_scope.customer.venderRate='';
                                    });
                                }
                                
                                var obj_sale = {
                                    companyId: add_scope.customer.select_store ? add_scope.customer.select_store.id : "",
                                    page: 1,
                                    rows: 999999,
                                    select_store: add_scope.customer.select_store
                                }
                                if (obj_sale.companyId&&obj_sale.select_store) {
                                    salesmanManageService.list(obj_sale).then(function(data) {
                                        add_scope.customer.select_sell = null;
                                        add_scope.sells = data.content;
                                    });
                                }
                                
                            }
                            add_scope.chooseCar = function() {
                                /*console.log(add_scope.cars);
                                for (var i = 0; i < add_scope.cars.length; i++) {
                                    if (add_scope.cars[i].checked) {
                                        add_scope.customer.dealerRate = add_scope.cars[i].dealerRate;
                                        add_scope.customer.clientRate = add_scope.cars[i].clientRate;
                                        add_scope.customer.venderRate = add_scope.cars[i].venderRate;
                                    }
                                }*/
                                // add_scope.choosePeriod();
                            }
                            add_scope.clientSelect = [],add_scope.dealerSelect = [],add_scope.venderSelect = [];
                            add_scope.choosePeriod = function(){
                                var carId = add_scope.customer.select_car ? add_scope.customer.select_car.id : "";
                                // var carId = "162";
                                if (!carId || !add_scope.customer.periods) {
                                    return false;
                                }
                                add_scope.clientSelect = [],add_scope.dealerSelect = [],add_scope.venderSelect = [];
                                add_scope.customer.clientRate ='',add_scope.customer.dealerRate='',add_scope.customer.venderRate='';
                                carManageService.getListByCarAndPeriods(carId,add_scope.customer.periods).then(function(data){
                                    if (data.length>0) {
                                        for (var i = 0; i < data.length; i++) {
                                            add_scope.clientSelect.push(data[i].clientRate);
                                            add_scope.dealerSelect.push(data[i].dealerRate);
                                            add_scope.venderSelect.push(data[i].venderRate);
                                        }
                                    }
                                });
                            }
                            add_scope.chooseClientFee = function(){
                                for (var i = 0; i < add_scope.clientSelect.length; i++) {
                                    if(add_scope.clientSelect[i] == add_scope.customer.clientRate){
                                        add_scope.customer.dealerRate = add_scope.dealerSelect[i];
                                        add_scope.customer.venderRate = add_scope.venderSelect[i];
                                        break;
                                    }
                                }
                                
                            }
                            add_scope.isSurchargeFn = function(){
                                add_scope.customer.isSurcharge = !add_scope.customer.isSurcharge;
                                /*if (add_scope.customer.isSurcharge) {
                                    add_scope.customer.surchargeDealerRate = add_scope.customer.dealerRate;
                                    add_scope.customer.surchargeClientRate = add_scope.customer.clientRate;
                                    add_scope.customer.surchargeVenderRate = add_scope.customer.venderRate;
                                    add_scope.customer.surchargePeriods = add_scope.customer.periods;
                                }else{
                                    add_scope.customer.surchargeDealerRate = "";
                                    add_scope.customer.surchargeClientRate = "";
                                    add_scope.customer.surchargeVenderRate = "";
                                    add_scope.customer.surchargePeriods = "";
                                }*/
                            }
                            add_scope.cancel = function() {
                                uibModal.close();
                            }
                            add_scope.ok = function() {
                                add_scope.customer.request_date_param = DPUtil.getDateToString(add_scope.customer.request_date);
                                add_scope.customer.into_date_param = DPUtil.getDateToString(add_scope.customer.into_date);
                                add_scope.customer.loan_date_param = DPUtil.getDateToString(add_scope.customer.loan_date);
                                add_scope.customer.credit_date_param = DPUtil.getDateToString(add_scope.customer.credit_date);
                               /* $scope.getItemKey($scope.g_clientType,add_scope.customer.clientProperty,add_scope.customer,"clientPropertyName");
                                $scope.getItemKey($scope.g_clientType,add_scope.customer.intoWay,add_scope.customer,"intoWayName");
                                $scope.getItemKey($scope.g_clientType,add_scope.customer.situation,add_scope.customer,"situationName");
                                $scope.getItemKey($scope.g_clientType,add_scope.customer.prequalification,add_scope.customer,"prequalificationName");
                                $scope.getItemKey($scope.g_clientType,add_scope.customer.the,add_scope.customer,"theName");*/
                                customerService.add(add_scope.customer).then(function(data) {
                                    if (data.success) {
                                        UIUtil.alert({ content: data.successMessage });
                                        uibModal.close();
                                        $scope.query();
                                    } else {
                                        UIUtil.alert({ content: data.failureMessage });
                                    }

                                });
                            }
                        }
                    ]
                });
            },
            showUpdate: function(data, stores, cars, sells,clientSelect) {
                $uibModal.open({
                    animation: true,
                    templateUrl: 'add.html',
                    keyboard: false,
                    backdrop: 'static',
                    size: "sg",
                    controller: ["$scope", "$uibModalInstance",
                        function(update_scope, uibModal) {
                            update_scope.g_clientType = $scope.g_clientType;
                            update_scope.g_document = $scope.g_document;
                            update_scope.g_condition = $scope.g_condition;
                            update_scope.g_preResult = $scope.g_preResult;
                            update_scope.g_finallyResult = $scope.g_finallyResult;
                            update_scope.g_periods = $scope.g_periods;

                            update_scope.clientSelect = [],update_scope.dealerSelect = [],update_scope.venderSelect = [];

                            update_scope.title = "修改";
                            update_scope.brands = $scope.brands;
                            update_scope.cars = cars;
                            update_scope.stores = stores;
                            update_scope.sells = sells;
                            update_scope.customer = data;
                            update_scope.clientSelect =clientSelect;
                            //修改获得数据初始化
                            update_scope.customer.clientProperty = "" + update_scope.customer.clientProperty;
                            update_scope.customer.intoWay = "" + update_scope.customer.intoWay;
                            update_scope.customer.isSurcharge = "" + update_scope.customer.isSurcharge;
                            update_scope.customer.prequalification = "" + update_scope.customer.prequalification;
                            update_scope.customer.the = "" + update_scope.customer.the;
                            update_scope.customer.isPledge = "" + update_scope.customer.isPledge;
                            update_scope.customer.request_date = new Date(update_scope.customer.requestDate);
                            update_scope.customer.into_date = new Date(update_scope.customer.intoDate);
                            update_scope.customer.loan_date = new Date(update_scope.customer.loanDate);
                            update_scope.customer.credit_date = new Date(update_scope.customer.creditDate);
                            update_scope.customer.brand_id = "" + update_scope.customer.brandId;
                            update_scope.customer.car_id = "" + update_scope.customer.carId;
                            update_scope.customer.company_id = "" + update_scope.customer.companyId;
                            update_scope.customer.sell_id = "" + update_scope.customer.sellId;
                            update_scope.customer.isSurcharge = update_scope.customer.isSurcharge != 0 ? true : false;
                            update_scope.customer.periods = "" + data.periods;
                            update_scope.customer.surchargePeriods = "" + data.surchargePeriods;
                            update_scope.customer.clientRate  = "" + update_scope.customer.clientRate;
                            update_scope.getStore = function() {
                                var param = update_scope.customer.select_brand ? update_scope.customer.select_brand.id : "";
                                if (param) {
                                    storeManageService.allList(param).then(function(data) {
                                        update_scope.customer.select_store = null;
                                        // update_scope.cars = [];
                                        // update_scope.sells = [];
                                        update_scope.stores = data;
                                        update_scope.customer.select_car = null;
                                        update_scope.cars = [];
                                        update_scope.customer.select_sell = null;
                                        update_scope.sells = [];
                                        update_scope.clientSelect = [];
                                        update_scope.customer.clientRate ='',update_scope.customer.dealerRate='',update_scope.customer.venderRate='';
                                    });
                                }
                                
                            }
                            update_scope.getCar = function() {
                                /*var obj = {
                                    brandId: update_scope.customer.select_brand.id,
                                    id: update_scope.customer.select_store ? update_scope.customer.select_store.id : "",
                                }
                                storeManageService.detail(obj).then(function(data) {
                                    for (var i = 0; i < data.length; i++) {
                                        data[i].id = data[i].carId;
                                        data[i].name = data[i].carName;
                                    }
                                    update_scope.customer.select_car = null;
                                    update_scope.cars = data;
                                });*/
                                var id = update_scope.customer.select_store ? update_scope.customer.select_store.id : ""
                                if (id) {
                                    carManageService.getListByCompany(id).then(function(data){
                                        update_scope.customer.select_car = null;
                                        update_scope.cars = data;
                                        update_scope.clientSelect = [];
                                        update_scope.customer.clientRate ='',update_scope.customer.dealerRate='',update_scope.customer.venderRate='';
                                    });
                                }
                                
                                var obj_sale = {
                                    companyId: update_scope.customer.select_store ? update_scope.customer.select_store.id : "",
                                    page: 1,
                                    rows: 999999,
                                    select_store: update_scope.customer.select_store
                                }
                                if (obj_sale.companyId&&obj_sale.select_store) {
                                    salesmanManageService.list(obj_sale).then(function(data) {
                                        update_scope.customer.select_sell = null;
                                        update_scope.sells = data.content;
                                    });
                                }
                                
                            }
                            update_scope.chooseCar = function() {
                                /*console.log(update_scope.cars);
                                for (var i = 0; i < update_scope.cars.length; i++) {
                                    if (update_scope.cars[i].checked) {
                                        update_scope.customer.dealerRate = update_scope.cars[i].dealerRate;
                                        update_scope.customer.clientRate = update_scope.cars[i].clientRate;
                                        update_scope.customer.venderRate = update_scope.cars[i].venderRate;
                                    }
                                }*/
                                // update_scope.choosePeriod();
                            }

                            
                            update_scope.chooseClientFee = function(){
                                for (var i = 0; i < update_scope.clientSelect.length; i++) {
                                    if(update_scope.clientSelect[i] == update_scope.customer.clientRate){
                                        update_scope.customer.dealerRate = update_scope.dealerSelect[i];
                                        update_scope.customer.venderRate = update_scope.venderSelect[i];
                                        break;
                                    }
                                }
                            }
                            update_scope.isSurchargeFn = function(update){
                                if (!update) {
                                    update_scope.customer.isSurcharge = !update_scope.customer.isSurcharge;
                                }
                                /*if (update_scope.customer.isSurcharge) {
                                    update_scope.customer.surchargeDealerRate = update_scope.customer.dealerRate;
                                    update_scope.customer.surchargeClientRate = update_scope.customer.clientRate;
                                    update_scope.customer.surchargeVenderRate = update_scope.customer.venderRate;
                                    update_scope.customer.surchargePeriods = update_scope.customer.periods;
                                }else{
                                    update_scope.customer.surchargeDealerRate = "";
                                    update_scope.customer.surchargeClientRate = "";
                                    update_scope.customer.surchargeVenderRate = "";
                                    update_scope.customer.surchargePeriods = "";
                                }*/
                            }
                            update_scope.choosePeriod = function(){
                                var carId = update_scope.customer.select_car ? update_scope.customer.select_car.id : "";
                                // var carId = "162";
                                if (!carId || !update_scope.customer.periods) {
                                    return false;
                                }
                                update_scope.clientSelect = [],update_scope.dealerSelect = [],update_scope.venderSelect = [];
                                update_scope.customer.clientRate ='',update_scope.customer.dealerRate='',update_scope.customer.venderRate='';
                                carManageService.getListByCarAndPeriods(carId,update_scope.customer.periods).then(function(data){
                                    if (data.length>0) {
                                        for (var i = 0; i < data.length; i++) {
                                            update_scope.clientSelect.push(data[i].clientRate);
                                            update_scope.dealerSelect.push(data[i].dealerRate);
                                            update_scope.venderSelect.push(data[i].venderRate);
                                        }
                                        update_scope.chooseClientFee();
                                        // update_scope.isSurchargeFn(true);
                                        
                                    }
                                });
                            }
                            // update_scope.choosePeriod();
                            // update_scope.isSurchargeFn(true);
                            update_scope.cancel = function() {
                                uibModal.close();
                            }
                            update_scope.ok = function() {
                                update_scope.customer.request_date_param = DPUtil.getDateToString(update_scope.customer.request_date);
                                update_scope.customer.into_date_param = DPUtil.getDateToString(update_scope.customer.into_date);
                                update_scope.customer.loan_date_param = DPUtil.getDateToString(update_scope.customer.loan_date);
                                update_scope.customer.credit_date_param = DPUtil.getDateToString(update_scope.customer.credit_date);
                                update_scope.customer.createdDate = DPUtil.getDateToString(new Date(update_scope.customer.createdDate));
                               /* $scope.getItemKey($scope.g_clientType,update_scope.customer.clientProperty,update_scope.customer,"clientPropertyName");
                                $scope.getItemKey($scope.g_clientType,update_scope.customer.intoWay,update_scope.customer,"intoWayName");
                                $scope.getItemKey($scope.g_clientType,update_scope.customer.situation,update_scope.customer,"situationName");
                                $scope.getItemKey($scope.g_clientType,update_scope.customer.prequalification,update_scope.customer,"prequalificationName");
                                $scope.getItemKey($scope.g_clientType,update_scope.customer.the,update_scope.customer,"theName");*/
                                customerService.update(update_scope.customer).then(function(data) {
                                    if (data.success) {
                                        UIUtil.alert({ content: data.successMessage });
                                        uibModal.close();
                                        $scope.query();
                                    } else {
                                        UIUtil.alert({ content: data.failureMessage });
                                    }
                                });
                            }
                        }
                    ]
                });
            },
            showDetail: function(data) {
                $uibModal.open({
                    animation: true,
                    templateUrl: 'detail.html',
                    keyboard: false,
                    backdrop: 'static',
                    size: "sg",
                    controller: ["$scope", "$uibModalInstance",
                        function(detail_scope, uibModal) {
                            detail_scope.customer = data;
                            detail_scope.g_clientType = $scope.g_clientType;
                            detail_scope.g_document = $scope.g_document;
                            detail_scope.g_condition = $scope.g_condition;
                            detail_scope.g_preResult = $scope.g_preResult;
                            detail_scope.g_finallyResult = $scope.g_finallyResult;
                            detail_scope.g_periods = $scope.g_periods;
                            detail_scope.getItemDetail = function(data,key,obj){
                                if (data.length>0) {
                                    for (var i = 0; i < data.length; i++) {
                                        if (obj[key]==data[i].value) {
                                            obj[key] = data[i].keyword;
                                            break;
                                        }
                                    }
                                }
                                
                            }
                            detail_scope.getItemDetail(detail_scope.g_clientType,"clientProperty",detail_scope.customer);
                            detail_scope.getItemDetail(detail_scope.g_document,"intoWay",detail_scope.customer);
                            detail_scope.getItemDetail(detail_scope.g_condition,"situation",detail_scope.customer);
                            detail_scope.getItemDetail(detail_scope.g_preResult,"prequalification",detail_scope.customer);
                            detail_scope.getItemDetail(detail_scope.g_finallyResult,"the",detail_scope.customer);
                            detail_scope.getItemDetail(detail_scope.g_periods,"periods",detail_scope.customer);
                            detail_scope.getItemDetail(detail_scope.g_periods,"surchargePeriods",detail_scope.customer);
                            detail_scope.cancel = function() {
                                uibModal.close();
                            }
                        }
                    ]
                });
            }
        }; //end _fn
    }
]);